package ma.ensao.evalmetrics.util.javaProjects;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
/*
*        Calcule TCC 
*/
public class TCCMetric {
	File sourceFile;
	double Tcc= 0;
	public double getTcc() {
		return Tcc;
	}
	public void setTcc(double Tcc) {
		this.Tcc = Tcc;
	}
	public TCCMetric(File file) throws FileNotFoundException, IOException{
		setSourceFile(file);
		JavaMethodsAttributes JM= new JavaMethodsAttributes(sourceFile);
		JM.setSourceFile(sourceFile);
		JM.countAttributes();
		JM.countPrivateAttributes();
		// Calcul du nombre de connexion directe
		double nmbre=0;
		for (int i = 0; i < JM.getNumberClasses(); i++) {
			if (JM.getNumberPrivateAttributes()[i]==0 || JM.getNumberAttributes()[i]==0){
				nmbre=0;
				Tcc +=nmbre; 
			}else{
				nmbre =(double) JM.getNumberPrivateAttributes()[i]/JM.getNumberAttributes()[i];
				Tcc +=nmbre; 
			}
		}
		// Calcul la moyenne de TCC
		System.out.println("Tccf"+Tcc);
		setTcc(Tcc/JM.getNumberClasses());
	}
	public File getSourceFile() {
		return sourceFile;
	}
	public void setSourceFile(File sourceFile) {
		this.sourceFile = sourceFile;
	}

}
